package cn.net.cfss.fgbp.provider.uid.config;

import cn.net.cfss.fgbp.base.constant.ErrCodeEnum;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@Slf4j
@RestControllerAdvice
public class ExceptionConf {

    /**
     * 全局异常捕捉处理
     *
     * @param ex
     * @return
     */

    @ExceptionHandler(value = Exception.class)
    public String errorHandler(Exception ex) {
        log.error("{}", ex.getStackTrace());
        JSONObject plainJson = new JSONObject();
        plainJson.put("resultCode", ErrCodeEnum.ERR.getValue());
        plainJson.put("resultMsg", "系统繁忙，请稍后再试");
        JSONObject packet = new JSONObject();
        packet.put("plain", plainJson);
        return packet.toJSONString();
    }

}
